package com.feng.controller;


import com.feng.entity.RestResponse;
import com.feng.entity.vo.CategoryAddVo;
import com.feng.entity.vo.CategoryPageReqVo;
import com.feng.entity.vo.UpdateRoleStatusReqVo;
import com.feng.service.CategoryService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/category")
public class CategoryController {

    final
    CategoryService categoryService;

    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @PreAuthorize("@ps.hasPermission('content:article:write')")
    @GetMapping("/allList")
    public RestResponse listAllCategory(){
        return categoryService.listAllCategory();
    }

    @PreAuthorize("@ps.hasPermission('system:category:query')")
    @PostMapping("/listAllCategory")
    public RestResponse listAllCategoryPage(@RequestBody CategoryPageReqVo categoryPage){
        return categoryService.listAllCategoryPage(categoryPage);
    }

    @PreAuthorize("@ps.hasPermission('system:category:edit')")
    @PutMapping("/updateStatus")
    public RestResponse updateStatus(@RequestBody UpdateRoleStatusReqVo updateStatus){
        return categoryService.updateStatus(updateStatus);
    }

    @PreAuthorize("@ps.hasPermission('system:category:edit')")
    @PostMapping("/addCategory")
    public RestResponse addCategory(@RequestBody CategoryAddVo categoryAdd){
        return categoryService.addCategory(categoryAdd);
    }

    @PreAuthorize("@ps.hasPermission('system:category:query')")
    @GetMapping("/{id}")
    public RestResponse getCategoryById(@PathVariable("id") Integer id){
        return categoryService.getCategoryById(id);
    }

    @PreAuthorize("@ps.hasPermission('system:category:edit')")
    @PutMapping("/updateCategory")
    public RestResponse updateCategory(@RequestBody CategoryAddVo categoryAdd){
        return categoryService.updateCategory(categoryAdd);
    }

    @PreAuthorize("@ps.hasPermission('system:category:remove')")
    @DeleteMapping("/deleteCategory/{id}")
    public RestResponse deleteCategory(@PathVariable("id") Long id){
        return categoryService.deleteCategory(id);
    }

    @PreAuthorize("@ps.hasPermission('system:category:remove')")
    @DeleteMapping("/delBatchCategory/{ids}")
    public RestResponse delBatchCategory(@PathVariable List<Long> ids){
        return categoryService.delBatchCategory(ids);
    }

    @PreAuthorize("@ps.hasPermission('system:category:export')")
    @GetMapping("/export")
    public void export(HttpServletResponse response){
        categoryService.export(response);
    }
}
